app.controller("roleController",function($scope, $http){
    $http({
        method: 'GET',
        url: '/OA/staff/list',
    }).success(function (response) {
        console.log(response)               //总条数
        $scope.total = response.data.list.length;
        //反转函数转化abcd转dcba
        $scope.data = response.data.list;
        //选择显示的条数
        $scope.values = [{"limit":6}];
        //默认显示的条数
        $scope.selectedLimit=$scope.values[0];
        //默认显示当前页数
        $scope.currentPage = 1;
        if($scope.data != null){
            $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.currentPage-1),$scope.selectedLimit.limit*$scope.currentPage);
        }else{
            alert($scope.data);
        }
        $scope.page = {
            "limit":$scope.selectedLimit.limit,"pageSize":5,"pageNo":$scope.currentPage,"totalCount":$scope.total};
        // 定义一个空对象 , 用于更新和保存数据时临时存储
        $scope.prod = {};
        $scope.arrs=response.data;
        console.log($scope.arrs)
        // 定义一个单击删除按钮时触发的事件，用于删除选中行
        $scope.delete = function($index){
            if ($index>=0) {
                if(confirm("是否删除"+$scope.arrs[$index].staffname+"的信息") ){
                    $scope.arrs.splice($index,1);
                    //将需要删除的卡号传给后台  2017/7/10
                    $http.post('recruit/transfer/test.json',{number:$scope.arrs[$index].number})
                        .success(function (result) {
                            if (result.success) {
                                alert(result.success)
                            }
                        }).error(function(result){
                        alert(result.error)
                    })
                }
            };
        }
        // 2017 7/11
        // 发布功能 guohongjun
        $scope.applyUp =function($index){
            if ($index>=0) {
                if (confirm("是否发布"+$scope.arrs[$index].name+"的课程")) {
                    $http.post('recruit/transfer/test.json',{number:$scope.arrs[$index].id}).then(function(project){
                        alert(project.success)
                    })
                };
            };
        }
        //定义一个全局变量idx  , 用于存储选中行的索引，方便执行保存操作时保存数据
        var idx = -1;
        //定义一个单击修改按钮时触发的事件，用于单击后弹出模块窗口用于修改报课单数据
        $scope.updata = function ($index) {
            //显示bootstrap中的模块窗口
            $('#staffmodify').modal('show');

            //将选中行的数据绑定到临时对象prod中，在下面的模态窗口中展示出来
            $scope.prod.order = $scope.arrs[$index].order;
            $scope.prod.number = $scope.arrs[$index].number;  //学号
            $scope.prod.card = $scope.arrs[$index].card;      //卡号
            $scope.prod.school = $scope.arrs[$index].school;  // 学校
            $scope.prod.type = $scope.arrs[$index].type;      //类别
            $scope.prod.people = $scope.arrs[$index].people;  //负责人
            $scope.prod.name = $scope.arrs[$index].name;      //姓名
            $scope.prod.date = $scope.arrs[$index].date;      //日期
            //选中行的索引赋值给全局变量idx
            idx = $index;
        };
        $scope.ToView=function($index){
            //将选中行的数据绑定到临时对象findview中，在下面的模态窗口中展示出来报课单
            $('#staffcheck').modal('show');
            $http({
                method: 'GET',
                url: 'recruit/withdraw/test.json'
            }).success(function (response){
                $scope.newdata=response.data.reverse();
                $scope.cosTiotion = $scope.newdata[$index].cosTiotion;
                $scope.elapsedTime = $scope.newdata[$index].elapsedTime;
                $scope.totalfees = $scope.newdata[$index].totalfees;
                $scope.class = $scope.newdata[$index].class;
                $scope.subject = $scope.newdata[$index].subject;
                $scope.originalType = $scope.newdata[$index].originalType;
                $scope.level = $scope.newdata[$index].level;
                $scope.card = $scope.newdata[$index].card;
                $scope.price = $scope.newdata[$index].price;
                $scope.classHour = $scope.newdata[$index].classHour;
                $scope.preferential = $scope.newdata[$index].preferential;
                $scope.classStudentName = $scope.newdata[$index].classStudentName;
                $scope.grade = $scope.newdata[$index].grade;
                $scope.school = $scope.newdata[$index].school;
                $scope.orgData = $scope.newdata[$index].orgData;
                $scope.transferData = $scope.newdata[$index].transferData;
                $scope.payment = $scope.newdata[$index].payment;
            })
        }


        //定义一个单机保存按钮时触发的事件,
        $scope.save = function () {
            //将修改后的值赋给数组
            $scope.arrs[idx].order = $scope.prod.order;
            $scope.arrs[idx].number = $scope.prod.number;
            $scope.arrs[idx].card = $scope.prod.card;
            $scope.arrs[idx].order = $scope.prod.order;
            $scope.arrs[idx].school = $scope.prod.school;
            $scope.arrs[idx].type = $scope.prod.type;
            $scope.arrs[idx].people = $scope.prod.people;
            $scope.arrs[idx].name = $scope.prod.name;
            $scope.arrs[idx].date = $scope.prod.date;
            //关闭模块窗口
            // 2017/7/10  保存后发送数据到后台修改数据库
            //guohongjun
            $http.post('recruit/transfer/test.json',{order:$scope.prod.order,number:$scope.prod.number,card:$scope.prod.card,school:$scope.prod.school,type:$scope.prod.type,people:$scope.prod.people,name:$scope.prod.name,date:$scope.prod.date})
                .success(function (result) {
                    if (result.success) {
                        alert(result.success)
                    }
                })
                .error(function(result){
                    alert(result.error)
                })
            $('#staffmodify').modal('hide');
        }
    })
    $scope.change = function(selectedLimit){
        $scope.page.limit = selectedLimit.limit;
        $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
    }
    $scope.pageChanged = function(){
        $scope.page.limit = $scope.selectedLimit.limit;
        $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
    }
    $scope.setPage = function (go) {
        $scope.length = Math.ceil($scope.total/$scope.selectedLimit.limit);
        console.log($scope.length);
        if(go > $scope.length){
            $scope.page.pageNo =  $scope.length;
            console.log($scope.length);

        }else{
            $scope.page.pageNo=go;
        }
        $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
    };
    $scope.clickFind=function(){
        var findVal=$("#findBlur").val();
        console.log(findVal)
        if (findVal=="") {
            return  false;
            console.log(findVal)
        }else{
            $http.post("recruit/transfer/oneToOne.json",{originalNumber:findVal}).success(function (response){
                $scope.originalType=response.data[0].originalType;
                $scope.level=response.data[0].level;
                $scope.card=response.data[0].card;
                $scope.price=response.data[0].price;
                $scope.classHour=response.data[0].classHour;
                $scope.classtotal=response.data[0].classtotal;
                $scope.preferential=response.data[0].preferential;
                $scope.studentName=response.data[0].studentName;
                $scope.grade=response.data[0].grade;
                $scope.school=response.data[0].school;
                $scope.campus=response.data[0].campus;
                $scope.orgData=response.data[0].orgData;
                $scope.transferData=response.data[0].transferData;
                $scope.payment=response.data[0].payment
            })
        };
    }
    $scope.addPost=function(){
        var findVal=$("#findBlur").val();
        if (findVal=="") {
            return false;
        }else {
            $scope.expendhours;  //已消耗小时数
            $scope.expendMoney;   //已消耗学费
            $scope.remainMoney;   // 可转学费
            $scope.turnLevel;    //欲转老师级别
            $scope.turnClassType;  //预转课程类型
            $scope.prerotationHours; //预转小时
            $scope.prerotationUnit;  //预转单价
            $scope.prerotationTution; //预转学费
            $scope.favorable;         //优惠
            $scope.needTution;       //需补学费
            $scope.needRefund;       //需退学费
            $scope.nowWay;          //现缴费方式
            $scope.nowCategory     //职务类别,
            $scope.nowHead   //负责人
            $scope.nowHeadmaster //校长
            $scope.nowStudentParents  //学生、家长
            $scope.checkedTure
            ///根据原报课单号查询数据
            $http.post("recruit/transfer/oneToOne.json",{originalNumber:findVal, //定义单号属性
                xpendhours:$scope.expendhours,
                expendMoney:$scope.expendMoney,
                remainMoney:$scope.remainMoney,
                turnLevel:$scope.turnLevel,
                turnClassType:$scope.turnClassType,
                prerotationHours:$scope.prerotationHours,
                prerotationUnit:$scope.prerotationUnit,
                prerotationTution:$scope.prerotationTution,
                favorable:$scope.favorable,
                needTution:$scope.needTution,
                needRefund:$scope.needRefund,
                nowWay:$scope.nowWay,
                nowCategory:$scope.nowCategory,
                nowHead:$scope.nowHead,
                nowHeadmaster:$scope.nowHeadmaster,
                nowStudentParents:$scope.nowHeadmaster,
                checkedTure:$scope.checkedTure
            }).success(function(response){
                alert(response.success)
            }).error(function(response){
                alert(response.error)
            })
        };
    }

    // 2017  7 /18
    // Create  guohongjun
    // 班课
    $scope.findClass=function(){
        var  findclass=$("#findclass").val();
        if (findclass=="") {
            return false;
        }else{
            $http.post("recruit/transfer/oneToOne.json",{classNumber:findclass}).success(function (response){
                $scope.applyTheClass=response.data[0].class;
                $scope.theApplySubject=response.data[0].subject;
                $scope.applySingTime=response.data[0].orgData;
                $scope.applyCostWay=response.data[0].payment;
                $scope.applyCartNumber=response.data[0].card;
                $scope.applyUnitPriceMoney=response.data[0].price;
                $scope.applyClassHours=response.data[0].classHour;
                $scope.applyTotalTuitionFees=response.data[0].totalfees;
                $scope.applyPreferential=response.data[0].preferential;
                $scope.applyNameClass=response.data[0].studentName;
                $scope.applyClassSchoole=response.data[0].school;
                $scope.applyClassCampus=response.data[0].campus;
                $scope.consumptionNumber=response.data[0].elapsedTime;
                $scope.classConsumptionMoney=response.data[0].cosTiotion;
                $scope.ConvertibleTuition=response.data[0].convertibleTuition;
            })
        };
    }
    // 班课发送后台数据
    $scope.classAdd=function(){
        var  findclass=$("#findclass").val();
        if (findclass=="") {
            return false;
        }else{
            $scope.wantTurnClassClass //  欲转报课班级
            $scope.nowSubjectPresentReport //现报科目
            $scope.wantTurnNumber  //预转次数
            $scope.wantTurnUnitPrice  //预转单价（次/小时）
            $scope.wantTurnMoney  //预转学费
            $scope.wantPreferential //优惠
            $scope.classNeedTuition //需补学费
            $scope.classNeedRefundTuition //需退学费
            $scope.classChecked //是否选中
            $scope.classNowCostWay //现缴费方式
            $scope.ClassJobCategory //职务类别
            $scope.nowClassHead  //负责人
            $scope.classHeadPeople //校长
            $scope.classStudentPreate //学生家长
            // 发送后台数据
            $http.post("recruit/transfer/oneToOne.json",{wantTurnClassClass:$scope.wantTurnClassClass,
                nowSubjectPresentReport:$scope.nowSubjectPresentReport,
                wantTurnNumber:$scope.wantTurnNumber,
                wantTurnUnitPrice:$scope.wantTurnUnitPrice,
                wantTurnMoney:$scope.wantTurnMoney,
                wantPreferential:$scope.wantPreferentia,
                classNeedTuition:$scope.classNeedTuition,
                classNeedRefundTuition:$scope.classNeedRefundTuition,
                classChecked:$scope.classChecked,
                classNowCostWay:$scope.classNowCostWay,
                ClassJobCategory:$scope.ClassJobCategory,
                nowClassHead:$scope.nowClassHead,
                classHeadPeople:$scope.classHeadPeople,
                classStudentPreate:$scope.classStudentPreate
            }).success(function (response){
                alert(response.success)
            }).error(function (response){
                alert(response.error)
            })
        };
    }
})

